package app.util;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.servlets.gzip.GzipHandler;

/*<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
</dependency>*/ 

public class FileServer {
	
	public static void main(String[] args) throws Exception {
		Server server = new Server(8083);
		
		ResourceHandler resourceHandler = new ResourceHandler();
		resourceHandler.setDirectoriesListed(true);
		resourceHandler.setWelcomeFiles(new String[]{ "index.html", "index.jsp" });
		//resourceHandler.setResourceBase("src/main/webapp/");
		resourceHandler.setResourceBase(".");
		
		GzipHandler gzip = new GzipHandler();
		server.setHandler(gzip);
		HandlerList handlers = new HandlerList();
		//官方文档说加DefaultHandler为了提供友好的404，但是加和不加没区别
		handlers.setHandlers(new Handler[]{ resourceHandler, new DefaultHandler() });
		gzip.setHandler(handlers);
		
		server.start();
		server.join();
	}
}
